package lib;

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Logger {

	private static SimpleDateFormat dateFormat = new SimpleDateFormat(Symbols.LOG_DATE_FORMAT);
	private static BufferedWriter out;

	public static void println(String line) {
		if(Symbols.DEBUG) {
			System.out.println(dateFormat.format(new Date()) + Symbols.LOG_TOKEN + line);
		}
		if(Symbols.LOG_TO_FILE) {
			write(line + "\n");
		}
	}

	public static void write(String line) {
		try {
			out = new BufferedWriter(new FileWriter(new File(Symbols.FILE_PATH), true));
			out.write(line);
			out.flush();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

}
